package com.learn.Controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/03/21
 * @description 在程序中获取国际化信息
 */
@RestController
public class LanguageController {
    @Autowired
    private MessageSource messageSource;
    @GetMapping("/message")
    public String getMsg(HttpServletRequest request) {
        // 传入三个参数 消息properties文件的键名，null，当前请求的语言区域
        return messageSource.getMessage("message.welcome", null, request.getLocale());
    }
}
